/* @INLINE FILE send_msgs.bloc.js =============================================================
	* Sending a chat message functions
	* 
	* VAR
	* this.textelem
	* 
	* FUNC
	* this.clearText
	* this.oKD - on key down
	* this.oKD2 - send typing event
    * this.refocus - focus on element after sending chat
    * this.releaseChat
    * this.releaseChat2
	* this.releaseOKD - release typing lock
	* this.sendMsgOnEnter
    * this.sendChat -  format and send chat msg
	*/
	
    this.textelem;
    
    this.clearText = function(){
    	jQ(_t.textelem).val('')
    };
    
    this.oKD = function(e) {
        var ev = window.event;
        if(ev){
        	if(ev.keyCode==13){
        		fc_chat.sendMsgOnEnter(ev.srcElement);
        	}
        }else{
        	if(e.which==13){
        		fc_chat.sendMsgOnEnter(e.target);
        	}
        }
    };
    
    this.oKD2 = function(e) {
        if ( ! l &&! lKD && config.showTyping) {
            req = '00001S';
            sendReq();
            lKD = true;
            setTimeout('fc_chat.releaseOKD()', 1000);
        };
    };
    
    this.refocus = function(typ,d,n){
    	var name='fc_uChat';
    	if(n){
    		name+='2';
    	}
    	var v = (typ ? $('fc_chat'): d.getElementById(name));
    	v.focus();
    };
    
    this.releaseChat = function(typ, d) {
        var v = (typ ? $('fc_sp1'): d.getElementById('fc_usp'));
        var spu = (typ ?'':'u');
        if (d == document) {
        		v[_i] = "<div class='fc_"+spu+"spbtn' >" +_v +(typ?private_button_layout:"")+" onClick='fc_chat.sendChat(" + typ + ",false,document);return false'>"+(typ?__(11):__(264,'Send Message'))+"</a></div>";
        } else {
        	v[_i] = "<div class='fc_"+spu+"spbtn' >" +_v +(typ?private_button_layout:"")+" onClick='window.parent.fc_chat.sendChat(" + typ + ",false,window.parent.fc_chat.getIFrameDoc());return false'>"+(typ?__(11):__(264,'Send Message'))+"</a></div>";
        }
    };
    
    this.releaseChat2 = function() {
        var v = $('fc_sg1');
        v[_i] = "<div class='fc_srbtn' >" +_v + private_button_layout +" onClick='fc_chat.sendChat(true,true,document);return false'>"+__(10)+"</a></div>";
    };
    
    this.releaseOKD = function() {
        lKD = false;
    };
    
    this.sendMsgOnEnter = function(target){
    	if(target.getAttribute('id')=='fc_chat'){
	    	if(sendMode==0){
		        if($('fc_sg1')[_i].indexOf("fc_srbtn_dis")==-1){
		        	this.sendChat(true, true, document,target);
		        }
	    	}else{
	    		if($('fc_sp1')[_i].indexOf("fc_spbtn_dis")==-1){
		        	this.sendChat(true, false, document,target);
		        }else{
		        	showInfo(__(389,"To send a message, highlight a user first. To add a user to your friends list, click on their screen name, and then select 'add to Friends'."));
		        }
	    	}
    	}else{
    		if(target.getAttribute('id')=='fc_uChat2'||$('fc_usp')[_i].indexOf("fc_uspbtn_dis")==-1){
	        	this.sendChat(false, false, document,target);
	        }
    	}
    };
    
    this.sendChat = function(typ, g, d, target) {
        var msg;
        var v;
        if(target){v=target}else{v=(typ ? $('fc_chat'): d.getElementById('fc_uChat'))};
        if ( ! l) {
            msg = v.value;
            msg = escapeStr(msg);
            if (config.allow_links) {
            	msg = urlify(msg);
        	}
            if (config.upload_images_enabled) {
                msg = msg.replace(/\[\[/g, '[[' + _t.uid + '_');
            }
            var mP = 0;
            var mPO = 0;
            while (true) {
                mP = msg.indexOf('{{');
                if (mP !=- 1 && mP >= mPO) {
                    mPO = mP;
                    mP = msg.indexOf('}}');
                    if (mP !=- 1 && mP >= mPO) {
                        var img = msg.substring(mPO + 2, mP);
                        var img2 = img.replace(/'/g, '\\\'');
                        if (smls[img2] != null) {
                            msg = msg.replace('{{' + img + '}}', '[[' + img + ']]');
                        }
                        mPO = mP;
                    } else {
                        break;
                    }
                } else {
                    break;
                }
            }
            msg = msg.replace(/^\s+/, '');
        	for (var i = msg.length - 1; i >= 0; i--) {
        		if (/\S/.test(msg.charAt(i))) {
        			msg = msg.substring(0, i + 1);
        			break;
        		}
        	}
        	if(!null_room()||!g){
	            if (msg.length > 0 && (msg.length>1 || msg.charCodeAt(0)!=10)) {
	                if (msg.length < config.max_chat_size) {
	                	if (!(g && is_guest(_t.uid)&&!config.guests_can_chat)){
		                	if (g || !is_guest((typ ? cPU: _t.cU))||a.o[(typ ? cPU: _t.cU)] == '1'){
		                		if (g || isAvl((typ ? cPU: _t.cU))){
		                			req=zpad_left(checkLength(msg)+10);
				                    if ( ! g) {
				                        var uStr = (typ ? cPU.toString(): _t.cU.toString());
				                        req += '8' + uStr.length + zpad_right(uStr);
				                    } else {
				                        req += '8000000000';
				                    }
				                    req += msg;
				                    sendReq();
				                    if(!target||target.getAttribute('id')!='fc_uChat2'){
					                    var v2;
					                    if ( ! g) {
					                        v2 = (typ ? $('fc_sp1'): d.getElementById('fc_usp'));
					                        var spu = (typ ?'':'u');
					                        v2[_i] = "<div class='fc_"+spu+"spbtn_dis' ><a class='fc_"+spu+"spbtn_disa' "+ (typ?private_button_layout:"")+">"+(typ?__(11):__(264,'Send Message'))+"</a></div>";
					                        
					                        if (d == document) {
					                           setTimeout('fc_chat.releaseChat(' + typ + ',document)', 500);
					                        } else {
					                           setTimeout('fc_chat.releaseChat(' + typ + ',fc_chat.getIFrameDoc())', 500);
					                        }
					                    } else {
					                        v2 = $('fc_sg1');
					                        v2[_i] = "<div class='fc_srbtn_dis' ><a class='fc_srbtn_disa'>"+__(10)+"</a></div>";
					                       setTimeout('fc_chat.releaseChat2()', 500);
					                    }
			                		}
			                	}else{
			                		showInfo(__(265,'Unable to send this message. The user is not available for chat.'));
			                	}
		                	}else{
		                		showInfo(__(130));
		                	}
		                }else{
	                		showChatInfo(__(410,'Please sign in to chat'),{x:40,y:EN(itext.style.top)-50});
	                	}
	                } else {
	                    showInfo(__(131) + config.max_chat_size + __(132));
	                }
	            } else {
	                showInfo(__(133));
	            }
        	}else {
                showChatInfo(__(411,'Please select a room'),{x:40,y:EN(itext.style.top)-50});
            }
            v.blur();
            _t.textelem=v;
            setTimeout('fc_chat.clearText()', 20);
            if(target&&target.getAttribute('id')=='fc_uChat2'){
            	setTimeout('fc_chat.refocus(' + typ + ',document,1)', 50);
            }else{
	            if (d == document) {
	            	setTimeout('fc_chat.refocus(' + typ + ',document)', 50);
	            } else {
	                setTimeout('fc_chat.refocus(' + typ + ',fc_chat.getIFrameDoc())', 50);
	            }
            }
        }
    };
    
    //send_msgs.bloc.js =============================================================@END FILE*/